home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 4
/
Amiga Tools 4.iso
/
tools
/
schulungen
/
dito
/
developer
/
demo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-27
|
3KB
|
104 lines
/*****************************/
/** DITO Demo **/
/** (C) Dirk Holtwick, 1996 **/
/*****************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// SOME USEFULL DEFINITIONS
#define FILEID "Italiano"
#define ITALIAN(d) (char *)(&d->str)
#define ENGLISH(d) (char *)(&d->str+d->ger)
#define TYPE(d) (d->type)
#define GR1(d) (char *)(&d->str+d->gr1)
#define GR2(d) (char *)(&d->str+d->gr2)
#define GRVAL1(d) (unsigned char)d->grv
#define GRVAL2(d) (unsigned char)d->grv2
#define GRVAL3(d) (unsigned char)d->grv3
#define READIMP(d) ((d->status & 6) >> 1)
#define READLND(d) (d->status & 1)
// WICH TYPE OF VOCABULARY IS IT?
char *Types[]={
"REST",
"NOUN",
"ADJECTIVE",
"VERB"
};
// HOW IMPORTANT?
char *Important[]={
"VERY IMPORTANT",
"NORMAL",
"NOT IMPORTANT"
};
// LEARNED?
char *Learned[]={
"NOT LEARNED",
"LEARNED"
};
// VOCABULARY STRUCTURE THAT IS USED BY ITALAIANO
struct VocData {
struct VocData *succ, *pred; // for list structure
long length; // lenth of structure
short type; // rest, noun, adjective or verb?
short status; // learned, weight
unsigned short ger, gr1, gr2; // offsets for strings
unsigned char grv, grv2, grv3; // some usefull datas
char str; // strings
};
// HERE STARTS THE SMALL DEMO THAT SHOWS YOU HOW TO LOAD A VOCFILE
void main(int argc, char *argv[]){
struct VocData *act;
long i, l, num;
char str[20];
FILE *in;
if(argc!=2){ // Need at least one argument
puts("USAGE: demo [vocfile]"); // like that
}else{ // otherwise start ...
if (in=fopen(argv[1],"rb")){ // Open file
fread(str,strlen(FILEID)+1,1,in); // Read ID
if(!strcmp(str,FILEID)){ // Is ID good?
fread(&num,4,1,in); // Read number of words
for(i=0;i<num;i++){ // Loop to read words
fread(&l,4,1,in); // How long are the following datas
act=malloc(l+sizeof(VocData)); // Allocate some memory
act->length=l; // Insert found length
fread(&act->type,l,1,in); // Read datas into structure
// SOME NICE OUTPUT
printf(
"Italian: %s\n"
"English: %s\n"
"Info: %s, %s, %s\n"
"Grammar: %s, %s, %d, %d,%d\n\n",
ITALIAN(act),
ENGLISH(act),
Types[TYPE(act)],
Important[READIMP(act)],
Learned[READLND(act)],
GR1(act), GR2(act),
GRVAL1(act), GRVAL2(act), GRVAL3(act));
free(act); // Free, because is only a demo
}
}else puts("Not an DITO file"); // Error DITO
fclose (in); // Close file
}else puts("Couldn't open file"); // Error message
}
}